package com.jelly.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.jelly.dto.Result;
import com.jelly.entity.MarkerPosition;
import com.jelly.query.CircleCenterQuery;
import com.jelly.query.MarkerPositionQuery;
import com.jelly.query.ShareForm;
import com.jelly.service.MarkerPositionService;
import com.jelly.util.UserHolder;
import com.jelly.vo.MarkersPosVo;

@RestController
@RequestMapping("/marker")
public class MarkerPositionController {

	@Resource
	private MarkerPositionService markerPositionService;

//	@GetMapping
//	public Result<PageData<MarkerPosition>> findPage(MarkerPositionQuery query) {
//		PageData<MarkerPosition> pageData = markerPositionService.findPage(query);
//		return Result<PageData<MarkerPosition>>().ok(pageData);
//	}
	@GetMapping("/findByUserId")
	public Result<List<MarkersPosVo>> findByUserId() {
		Long userId = UserHolder.getHolder();
		List<MarkersPosVo> list = markerPositionService.findByUserId(userId);
		return Result.success(list);
	}

	@PostMapping("/add")
	public Result<String> add(@RequestBody MarkerPosition markers) {
		Long userId = UserHolder.getHolder();
		markers.setUserId(userId);
		markerPositionService.addMarkerPosition(markers);
		return Result.success("添加成功");
	}

	@GetMapping("/all")
	public Result<List<MarkersPosVo>> findAll() {
		List<MarkersPosVo> data = markerPositionService.finAll();
		return Result.success(data);
	}

	@GetMapping("/circle/search")
	public Result<List<MarkersPosVo>> findMarkersByCircle(CircleCenterQuery query) {
		List<MarkersPosVo> result = markerPositionService.findMarkersByCircle(query);
		return Result.success(result);
	}

	@GetMapping("/findById")
	public Result<MarkerPosition> findById(Long markerId) {
		MarkerPosition position = markerPositionService.findById(markerId);
		return Result.success(position);
	}

	@PostMapping("/share")
	public Result<Object> sharePoint(@RequestBody ShareForm form) {
		markerPositionService.sharePoint(form);
		return Result.success();
	}

	@PostMapping("/update")
	public Result<Object> updatePoint(@RequestBody MarkerPosition position) {
		markerPositionService.updatePoint(position);
		return Result.success();
	}

	@DeleteMapping("/delete/{id}")
	public Result<Object> deletePoint(@PathVariable("id") Long id) {
		markerPositionService.deletePoint(id);
		return Result.success();
	}

	@GetMapping("/findPointByUserId")
	public Result<List<MarkerPosition>> findPointByUserId() {
		Long userId = UserHolder.getHolder();
		List<MarkerPosition> list = markerPositionService.findPointByUserId(userId);
		return Result.success(list);
	}
}
